import Utils from '../utils.js'
import { iframeMediaOrigin } from '../api.config.js'
export default {
	init: function() {
		let _this = this;
		let obj = {
			nickNameObj: $(".nickName"),
			appIdObj: $(".appId"),
			userIdObj: $(".userId"),
			accessTokenObj: $(".accessToken"),
			selfSelectObj: $(".selfSelect"),
			inputBoxObj: $(".show_input_box"),
			accessTokenObj: $(".accessToken")
		};
		// 认证
		$(".confirmBtn").on("click", function(e) {
			let nickName = obj.nickNameObj.val();
			if(!Utils._spaceCheck(nickName)) {
				$.message({message: '输出名称不能为空!', type: 'info'});
				return;
			}
			if(!Utils._check1_32Num(nickName)) {
				$.message({message: '请输入长度为1到32位的昵称!', type: 'info'});
				return;
			}
			if(nickName.toLowerCase() == null) {
				$.message({message: '输出名称非法!', type: 'info'});
				return;
			}
			_this.toConfirm();
		});
		// 保存
		$(".saveBtn").on("click", function(e) {
			let nickName = obj.nickNameObj.val();
			let appId = obj.appIdObj.val();
			let userId = obj.userIdObj.val();
			let accessToken = obj.accessTokenObj.val();
			let isAuto = obj.selfSelectObj.attr("data-value") == "Automation"? '0' : '1';
			if(!Utils._spaceCheck(nickName)) {
				$.message({message: '输出名称不能为空!', type: 'info'});
				return;
			}
			if(!Utils._check1_32Num(nickName)) {
				$.message({message: '请输入长度为1到32位的昵称!', type: 'info'});
				return;
			}
			if(nickName.toLowerCase() == null) {
				$.message({message: '输出名称非法!', type: 'info'});
				return;
			}
			if(isAuto == '1') {
				if(!Utils._spaceCheck(appId)) {
					$.message({message: 'AppID不能为空!', type: 'info'});
					return;
				}
				if(!Utils._spaceCheck(userId)) {
					$.message({message: '用户ID不能为空!', type: 'info'});
					return;
				}
				if(!Utils._spaceCheck(accessToken)) {
					$.message({message: 'Access Token不能为空!', type: 'info'});
					return;
				}
				if(!Utils._check6_32Num(userId)) {
					$.message({message: '请输入6-32位的数字用户ID!', type: 'info'});
					return;
				}
			}
			_this.saveAuthInfo(obj);
		});
		// 取消
		$(".quitBtn,.closeBtn").on("click", function(e) {
			Utils._closeParent("facebookAdd");
		});
		// 切换radio
		$(".selfSelect li").on("click", function() {
			Utils._changeRadio($(this), "toggleShow");
		});
		// 切换Stream查看状态
		$(".eyeIcon").on("click", function() {
			Utils._changeInput($(this), obj.accessTokenObj);
		});
	},
	toConfirm: function () {
	},
	saveAuthInfo: function() {
		// let token = Utils._getAesString(streamName, pwd_1, iv_1);
		// let obj = {
		// 	nickName: nickName,
		// 	isAuto: isAuto,
		// 	type: "Y",
		// 	token: token,
		// 	rtmpId: serverUrl,
		// 	shareType: isAuto == '0' ? 1: 0
		// }
	}
}